{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "eb450cca-f749-4654-9e74-10982ed47014",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5083d368-a005-4267-861b-8c79f4621ec8",
   "metadata": {},
   "source": [
    "# 特殊的NumPy帮助功能"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8006eec7-8507-42e3-b1da-8ef82cf381bc",
   "metadata": {},
   "source": [
    "## 查找帮助\n",
    "\n",
    "方法|描述\n",
    "--:|:--\n",
    "lookfor(what[, module, import_modules, …])|对文档字符串执行关键字搜索。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cc814f7f-5eb7-4f46-bed1-b22491d9c644",
   "metadata": {},
   "source": [
    "## 阅读帮助\n",
    "\n",
    "方法|描述\n",
    "--:|:--\n",
    "info([object, maxwidth, output, toplevel])|获取函数、类或模块的帮助信息。\n",
    "source(object[, output])|打印NumPy对象的源代码或将其写入文件。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edfd0cff-6e81-43fe-822b-e9c59c4fa93f",
   "metadata": {},
   "source": [
    "### numpy.info(object=None, maxwidth=76, output=None, toplevel='numpy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c782db62-3e3d-463a-9aca-030185cdad3a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " polyval(p, x)\n",
      "\n",
      "Evaluate a polynomial at specific values.\n",
      "\n",
      ".. note::\n",
      "   This forms part of the old polynomial API. Since version 1.4, the\n",
      "   new polynomial API defined in `numpy.polynomial` is preferred.\n",
      "   A summary of the differences can be found in the\n",
      "   :doc:`transition guide </reference/routines.polynomials>`.\n",
      "\n",
      "If `p` is of length N, this function returns the value:\n",
      "\n",
      "    ``p[0]*x**(N-1) + p[1]*x**(N-2) + ... + p[N-2]*x + p[N-1]``\n",
      "\n",
      "If `x` is a sequence, then ``p(x)`` is returned for each element of ``x``.\n",
      "If `x` is another polynomial then the composite polynomial ``p(x(t))``\n",
      "is returned.\n",
      "\n",
      "Parameters\n",
      "----------\n",
      "p : array_like or poly1d object\n",
      "   1D array of polynomial coefficients (including coefficients equal\n",
      "   to zero) from highest degree to the constant term, or an\n",
      "   instance of poly1d.\n",
      "x : array_like or poly1d object\n",
      "   A number, an array of numbers, or an instance of poly1d, at\n",
      "   which to evaluate `p`.\n",
      "\n",
      "Returns\n",
      "-------\n",
      "values : ndarray or poly1d\n",
      "   If `x` is a poly1d instance, the result is the composition of the two\n",
      "   polynomials, i.e., `x` is \"substituted\" in `p` and the simplified\n",
      "   result is returned. In addition, the type of `x` - array_like or\n",
      "   poly1d - governs the type of the output: `x` array_like => `values`\n",
      "   array_like, `x` a poly1d object => `values` is also.\n",
      "\n",
      "See Also\n",
      "--------\n",
      "poly1d: A polynomial class.\n",
      "\n",
      "Notes\n",
      "-----\n",
      "Horner's scheme [1]_ is used to evaluate the polynomial. Even so,\n",
      "for polynomials of high degree the values may be inaccurate due to\n",
      "rounding errors. Use carefully.\n",
      "\n",
      "If `x` is a subtype of `ndarray` the return value will be of the same type.\n",
      "\n",
      "References\n",
      "----------\n",
      ".. [1] I. N. Bronshtein, K. A. Semendyayev, and K. A. Hirsch (Eng.\n",
      "   trans. Ed.), *Handbook of Mathematics*, New York, Van Nostrand\n",
      "   Reinhold Co., 1985, pg. 720.\n",
      "\n",
      "Examples\n",
      "--------\n",
      ">>> np.polyval([3,0,1], 5)  # 3 * 5**2 + 0 * 5**1 + 1\n",
      "76\n",
      ">>> np.polyval([3,0,1], np.poly1d(5))\n",
      "poly1d([76])\n",
      ">>> np.polyval(np.poly1d([3,0,1]), 5)\n",
      "76\n",
      ">>> np.polyval(np.poly1d([3,0,1]), np.poly1d(5))\n",
      "poly1d([76])\n"
     ]
    }
   ],
   "source": [
    "np.info(np.polyval)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "632961ee-2e2b-486b-b024-931dee05ebc7",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     *** Found in numpy ***\n",
      "Discrete Fourier Transform (:mod:`numpy.fft`)\n",
      "=============================================\n",
      "\n",
      ".. currentmodule:: numpy.fft\n",
      "\n",
      "The SciPy module `scipy.fft` is a more comprehensive superset\n",
      "of ``numpy.fft``, which includes only a basic set of routines.\n",
      "\n",
      "Standard FFTs\n",
      "-------------\n",
      "\n",
      ".. autosummary::\n",
      "   :toctree: generated/\n",
      "\n",
      "   fft       Discrete Fourier transform.\n",
      "   ifft      Inverse discrete Fourier transform.\n",
      "   fft2      Discrete Fourier transform in two dimensions.\n",
      "   ifft2     Inverse discrete Fourier transform in two dimensions.\n",
      "   fftn      Discrete Fourier transform in N-dimensions.\n",
      "   ifftn     Inverse discrete Fourier transform in N dimensions.\n",
      "\n",
      "Real FFTs\n",
      "---------\n",
      "\n",
      ".. autosummary::\n",
      "   :toctree: generated/\n",
      "\n",
      "   rfft      Real discrete Fourier transform.\n",
      "   irfft     Inverse real discrete Fourier transform.\n",
      "   rfft2     Real discrete Fourier transform in two dimensions.\n",
      "   irfft2    Inverse real discrete Fourier transform in two dimensions.\n",
      "   rfftn     Real discrete Fourier transform in N dimensions.\n",
      "   irfftn    Inverse real discrete Fourier transform in N dimensions.\n",
      "\n",
      "Hermitian FFTs\n",
      "--------------\n",
      "\n",
      ".. autosummary::\n",
      "   :toctree: generated/\n",
      "\n",
      "   hfft      Hermitian discrete Fourier transform.\n",
      "   ihfft     Inverse Hermitian discrete Fourier transform.\n",
      "\n",
      "Helper routines\n",
      "---------------\n",
      "\n",
      ".. autosummary::\n",
      "   :toctree: generated/\n",
      "\n",
      "   fftfreq   Discrete Fourier Transform sample frequencies.\n",
      "   rfftfreq  DFT sample frequencies (for usage with rfft, irfft).\n",
      "   fftshift  Shift zero-frequency component to center of spectrum.\n",
      "   ifftshift Inverse of fftshift.\n",
      "\n",
      "\n",
      "Background information\n",
      "----------------------\n",
      "\n",
      "Fourier analysis is fundamentally a method for expressing a function as a\n",
      "sum of periodic components, and for recovering the function from those\n",
      "components.  When both the function and its Fourier transform are\n",
      "replaced with discretized counterparts, it is called the discrete Fourier\n",
      "transform (DFT).  The DFT has become a mainstay of numerical computing in\n",
      "part because of a very fast algorithm for computing it, called the Fast\n",
      "Fourier Transform (FFT), which was known to Gauss (1805) and was brought\n",
      "to light in its current form by Cooley and Tukey [CT]_.  Press et al. [NR]_\n",
      "provide an accessible introduction to Fourier analysis and its\n",
      "applications.\n",
      "\n",
      "Because the discrete Fourier transform separates its input into\n",
      "components that contribute at discrete frequencies, it has a great number\n",
      "of applications in digital signal processing, e.g., for filtering, and in\n",
      "this context the discretized input to the transform is customarily\n",
      "referred to as a *signal*, which exists in the *time domain*.  The output\n",
      "is called a *spectrum* or *transform* and exists in the *frequency\n",
      "domain*.\n",
      "\n",
      "Implementation details\n",
      "----------------------\n",
      "\n",
      "There are many ways to define the DFT, varying in the sign of the\n",
      "exponent, normalization, etc.  In this implementation, the DFT is defined\n",
      "as\n",
      "\n",
      ".. math::\n",
      "   A_k =  \\sum_{m=0}^{n-1} a_m \\exp\\left\\{-2\\pi i{mk \\over n}\\right\\}\n",
      "   \\qquad k = 0,\\ldots,n-1.\n",
      "\n",
      "The DFT is in general defined for complex inputs and outputs, and a\n",
      "single-frequency component at linear frequency :math:`f` is\n",
      "represented by a complex exponential\n",
      ":math:`a_m = \\exp\\{2\\pi i\\,f m\\Delta t\\}`, where :math:`\\Delta t`\n",
      "is the sampling interval.\n",
      "\n",
      "The values in the result follow so-called \"standard\" order: If ``A =\n",
      "fft(a, n)``, then ``A[0]`` contains the zero-frequency term (the sum of\n",
      "the signal), which is always purely real for real inputs. Then ``A[1:n/2]``\n",
      "contains the positive-frequency terms, and ``A[n/2+1:]`` contains the\n",
      "negative-frequency terms, in order of decreasingly negative frequency.\n",
      "For an even number of input points, ``A[n/2]`` represents both positive and\n",
      "negative Nyquist frequency, and is also purely real for real input.  For\n",
      "an odd number of input points, ``A[(n-1)/2]`` contains the largest positive\n",
      "frequency, while ``A[(n+1)/2]`` contains the largest negative frequency.\n",
      "The routine ``np.fft.fftfreq(n)`` returns an array giving the frequencies\n",
      "of corresponding elements in the output.  The routine\n",
      "``np.fft.fftshift(A)`` shifts transforms and their frequencies to put the\n",
      "zero-frequency components in the middle, and ``np.fft.ifftshift(A)`` undoes\n",
      "that shift.\n",
      "\n",
      "When the input `a` is a time-domain signal and ``A = fft(a)``, ``np.abs(A)``\n",
      "is its amplitude spectrum and ``np.abs(A)**2`` is its power spectrum.\n",
      "The phase spectrum is obtained by ``np.angle(A)``.\n",
      "\n",
      "The inverse DFT is defined as\n",
      "\n",
      ".. math::\n",
      "   a_m = \\frac{1}{n}\\sum_{k=0}^{n-1}A_k\\exp\\left\\{2\\pi i{mk\\over n}\\right\\}\n",
      "   \\qquad m = 0,\\ldots,n-1.\n",
      "\n",
      "It differs from the forward transform by the sign of the exponential\n",
      "argument and the default normalization by :math:`1/n`.\n",
      "\n",
      "Type Promotion\n",
      "--------------\n",
      "\n",
      "`numpy.fft` promotes ``float32`` and ``complex64`` arrays to ``float64`` and\n",
      "``complex128`` arrays respectively. For an FFT implementation that does not\n",
      "promote input arrays, see `scipy.fftpack`.\n",
      "\n",
      "Normalization\n",
      "-------------\n",
      "\n",
      "The argument ``norm`` indicates which direction of the pair of direct/inverse\n",
      "transforms is scaled and with what normalization factor.\n",
      "The default normalization (``\"backward\"``) has the direct (forward) transforms\n",
      "unscaled and the inverse (backward) transforms scaled by :math:`1/n`. It is\n",
      "possible to obtain unitary transforms by setting the keyword argument ``norm``\n",
      "to ``\"ortho\"`` so that both direct and inverse transforms are scaled by\n",
      ":math:`1/\\sqrt{n}`. Finally, setting the keyword argument ``norm`` to\n",
      "``\"forward\"`` has the direct transforms scaled by :math:`1/n` and the inverse\n",
      "transforms unscaled (i.e. exactly opposite to the default ``\"backward\"``).\n",
      "`None` is an alias of the default option ``\"backward\"`` for backward\n",
      "compatibility.\n",
      "\n",
      "Real and Hermitian transforms\n",
      "-----------------------------\n",
      "\n",
      "When the input is purely real, its transform is Hermitian, i.e., the\n",
      "component at frequency :math:`f_k` is the complex conjugate of the\n",
      "component at frequency :math:`-f_k`, which means that for real\n",
      "inputs there is no information in the negative frequency components that\n",
      "is not already available from the positive frequency components.\n",
      "The family of `rfft` functions is\n",
      "designed to operate on real inputs, and exploits this symmetry by\n",
      "computing only the positive frequency components, up to and including the\n",
      "Nyquist frequency.  Thus, ``n`` input points produce ``n/2+1`` complex\n",
      "output points.  The inverses of this family assumes the same symmetry of\n",
      "its input, and for an output of ``n`` points uses ``n/2+1`` input points.\n",
      "\n",
      "Correspondingly, when the spectrum is purely real, the signal is\n",
      "Hermitian.  The `hfft` family of functions exploits this symmetry by\n",
      "using ``n/2+1`` complex points in the input (time) domain for ``n`` real\n",
      "points in the frequency domain.\n",
      "\n",
      "In higher dimensions, FFTs are used, e.g., for image analysis and\n",
      "filtering.  The computational efficiency of the FFT means that it can\n",
      "also be a faster way to compute large convolutions, using the property\n",
      "that a convolution in the time domain is equivalent to a point-by-point\n",
      "multiplication in the frequency domain.\n",
      "\n",
      "Higher dimensions\n",
      "-----------------\n",
      "\n",
      "In two dimensions, the DFT is defined as\n",
      "\n",
      ".. math::\n",
      "   A_{kl} =  \\sum_{m=0}^{M-1} \\sum_{n=0}^{N-1}\n",
      "   a_{mn}\\exp\\left\\{-2\\pi i \\left({mk\\over M}+{nl\\over N}\\right)\\right\\}\n",
      "   \\qquad k = 0, \\ldots, M-1;\\quad l = 0, \\ldots, N-1,\n",
      "\n",
      "which extends in the obvious way to higher dimensions, and the inverses\n",
      "in higher dimensions also extend in the same way.\n",
      "\n",
      "References\n",
      "----------\n",
      "\n",
      ".. [CT] Cooley, James W., and John W. Tukey, 1965, \"An algorithm for the\n",
      "        machine calculation of complex Fourier series,\" *Math. Comput.*\n",
      "        19: 297-301.\n",
      "\n",
      ".. [NR] Press, W., Teukolsky, S., Vetterline, W.T., and Flannery, B.P.,\n",
      "        2007, *Numerical Recipes: The Art of Scientific Computing*, ch.\n",
      "        12-13.  Cambridge Univ. Press, Cambridge, UK.\n",
      "\n",
      "Examples\n",
      "--------\n",
      "\n",
      "For examples, see the various functions.\n",
      "----------------------------------------------------------------------------\n",
      "     *** Found in numpy.fft ***\n",
      " fft(a, n=None, axis=-1, norm=None)\n",
      "\n",
      "Compute the one-dimensional discrete Fourier Transform.\n",
      "\n",
      "This function computes the one-dimensional *n*-point discrete Fourier\n",
      "Transform (DFT) with the efficient Fast Fourier Transform (FFT)\n",
      "algorithm [CT].\n",
      "\n",
      "Parameters\n",
      "----------\n",
      "a : array_like\n",
      "    Input array, can be complex.\n",
      "n : int, optional\n",
      "    Length of the transformed axis of the output.\n",
      "    If `n` is smaller than the length of the input, the input is cropped.\n",
      "    If it is larger, the input is padded with zeros.  If `n` is not given,\n",
      "    the length of the input along the axis specified by `axis` is used.\n",
      "axis : int, optional\n",
      "    Axis over which to compute the FFT.  If not given, the last axis is\n",
      "    used.\n",
      "norm : {\"backward\", \"ortho\", \"forward\"}, optional\n",
      "    .. versionadded:: 1.10.0\n",
      "\n",
      "    Normalization mode (see `numpy.fft`). Default is \"backward\".\n",
      "    Indicates which direction of the forward/backward pair of transforms\n",
      "    is scaled and with what normalization factor.\n",
      "\n",
      "    .. versionadded:: 1.20.0\n",
      "\n",
      "        The \"backward\", \"forward\" values were added.\n",
      "\n",
      "Returns\n",
      "-------\n",
      "out : complex ndarray\n",
      "    The truncated or zero-padded input, transformed along the axis\n",
      "    indicated by `axis`, or the last one if `axis` is not specified.\n",
      "\n",
      "Raises\n",
      "------\n",
      "IndexError\n",
      "    If `axis` is not a valid axis of `a`.\n",
      "\n",
      "See Also\n",
      "--------\n",
      "numpy.fft : for definition of the DFT and conventions used.\n",
      "ifft : The inverse of `fft`.\n",
      "fft2 : The two-dimensional FFT.\n",
      "fftn : The *n*-dimensional FFT.\n",
      "rfftn : The *n*-dimensional FFT of real input.\n",
      "fftfreq : Frequency bins for given FFT parameters.\n",
      "\n",
      "Notes\n",
      "-----\n",
      "FFT (Fast Fourier Transform) refers to a way the discrete Fourier\n",
      "Transform (DFT) can be calculated efficiently, by using symmetries in the\n",
      "calculated terms.  The symmetry is highest when `n` is a power of 2, and\n",
      "the transform is therefore most efficient for these sizes.\n",
      "\n",
      "The DFT is defined, with the conventions used in this implementation, in\n",
      "the documentation for the `numpy.fft` module.\n",
      "\n",
      "References\n",
      "----------\n",
      ".. [CT] Cooley, James W., and John W. Tukey, 1965, \"An algorithm for the\n",
      "        machine calculation of complex Fourier series,\" *Math. Comput.*\n",
      "        19: 297-301.\n",
      "\n",
      "Examples\n",
      "--------\n",
      ">>> np.fft.fft(np.exp(2j * np.pi * np.arange(8) / 8))\n",
      "array([-2.33486982e-16+1.14423775e-17j,  8.00000000e+00-1.25557246e-15j,\n",
      "        2.33486982e-16+2.33486982e-16j,  0.00000000e+00+1.22464680e-16j,\n",
      "       -1.14423775e-17+2.33486982e-16j,  0.00000000e+00+5.20784380e-16j,\n",
      "        1.14423775e-17+1.14423775e-17j,  0.00000000e+00+1.22464680e-16j])\n",
      "\n",
      "In this example, real input has an FFT which is Hermitian, i.e., symmetric\n",
      "in the real part and anti-symmetric in the imaginary part, as described in\n",
      "the `numpy.fft` documentation:\n",
      "\n",
      ">>> import matplotlib.pyplot as plt\n",
      ">>> t = np.arange(256)\n",
      ">>> sp = np.fft.fft(np.sin(t))\n",
      ">>> freq = np.fft.fftfreq(t.shape[-1])\n",
      ">>> plt.plot(freq, sp.real, freq, sp.imag)\n",
      "[<matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...>]\n",
      ">>> plt.show()\n",
      "----------------------------------------------------------------------------\n",
      "\n",
      "     *** Repeat reference found in numpy.fft._pocketfft *** \n",
      "\n",
      "     *** Total of 3 references found. ***\n"
     ]
    }
   ],
   "source": [
    "np.info('fft') "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4ca2ce45-bff7-4dae-ab8e-abcd15b25373",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "class:  ndarray\n",
      "shape:  (2, 3)\n",
      "strides:  (24, 8)\n",
      "itemsize:  8\n",
      "aligned:  True\n",
      "contiguous:  True\n",
      "fortran:  False\n",
      "data pointer: 0x1572130\n",
      "byteorder:  little\n",
      "byteswap:  False\n",
      "type: complex64\n"
     ]
    }
   ],
   "source": [
    "a = np.array([[1 + 2j, 3, -4], [-5j, 6, 0]], dtype=np.complex64)\n",
    "np.info(a)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
